package neu.soft.message;

import neu.soft.entity.NormalOrder;
import neu.soft.service.impl.DistributionTaskOrderServiceImpl;
import neu.soft.vo.MsgBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Service;

@Service
public class Listener {

    @Autowired
    private DistributionTaskOrderServiceImpl distributionTaskOrderService;

    @StreamListener("send-common")
    public void receive(@Payload MsgBean msgBean) {
        System.out.println(msgBean);
        String ord = msgBean.getData().toString();
        NormalOrder n = new NormalOrder();
        n.setOid(ord);
        try {
            distributionTaskOrderService.autoCreateDistributionTaskOrder(n);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    //    @StreamListener("distribution-common")
//    public void asd(@Payload MsgBean msgBean){
//        System.out.println("------------");
//        System.out.println(msgBean);
//        System.out.println("***********");
//    }
    @StreamListener("create-order")
    public void receiveOrder(@Payload MsgBean msgBean) {
        System.out.println(msgBean);
    }
}